package com.wangshupo.app.geekpark.control;

import com.wangshupo.app.geekpark.model.News;
import com.wangshupo.app.geekpark.param.NewsQueryParam;
import com.wangshupo.app.geekpark.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/news/api")
public class NewsTest {
    @Autowired
    private NewsService newsService;

    @GetMapping("/test")
    public Map testNews(){
        Map resultData = new HashMap<>();  //存储结果

        News news = new News();
        news.setTitle("极客新闻的帅哥美女1111111");
        news.setType("HomePart__and__Part__WANGSHUPO");

        News news1 = newsService.addNews(news); //添加一个news，并自动添加一个主键,每添加一个对象就添加一个主键
        resultData.put("news1",news1);

        NewsQueryParam param = new NewsQueryParam();
        param.setPageNum(1);
        param.setPageSize(5);

        Page<News> pageData = newsService.list(param);  //查询所有数据
        List<News> content = pageData.getContent();
        resultData.put("pageData",content);


        return resultData;
    }
}
